import pytest
from common.request_util_test import RequestUtil
from common.test_yaml_util_test import YamlUtil
from config import datas


class Testevent:
    url_unify = "/clusters/host"

    @pytest.mark.normal
    @pytest.mark.k8sresource
    @pytest.mark.event
    @pytest.mark.parametrize('eventinfo',
                             YamlUtil().read_testcase_yaml('v25.06/resourcemanage/event/1_get_event_list.yaml'))
    def test_get_event_list(self, eventinfo):
        # 获取event列表接口-正常
        base_url = datas.baseUrl + Testevent.url_unify
        url = base_url + eventinfo['request']['url']
        method = eventinfo['request']['method']
        req = RequestUtil().send_request(method, url)
        assert req.status_code == eventinfo['validate'][0]['equals']['status_code']

    @pytest.mark.abnormal
    @pytest.mark.k8sresource
    @pytest.mark.event
    @pytest.mark.parametrize('eventinfo', YamlUtil().read_testcase_yaml(
        'v25.06/resourcemanage/event/1_get_event_list_exception.yaml'))
    def test_get_event_list_exception(self, eventinfo):
        # 获取event列表接口-异常
        base_url = datas.baseUrl + Testevent.url_unify
        url = base_url + eventinfo['request']['url']
        method = eventinfo['request']['method']
        req = RequestUtil().send_request(method, url)
        assert req.status_code == eventinfo['validate'][0]['equals']['status_code']

    @pytest.mark.normal
    @pytest.mark.k8sresource
    @pytest.mark.event
    @pytest.mark.parametrize('eventinfo',
                             YamlUtil().read_testcase_yaml('v25.06/resourcemanage/event/2_get_event_by_kind.yaml'))
    def test_get_event_by_kind(self, eventinfo):
        # 通过类型查找event-正常
        base_url = datas.baseUrl + Testevent.url_unify
        url = base_url + eventinfo['request']['url'].replace('{kind}', 'Pod')
        method = eventinfo['request']['method']
        req = RequestUtil().send_request(method, url)
        assert req.status_code == eventinfo['validate'][0]['equals']['status_code']

    @pytest.mark.abnormal
    @pytest.mark.k8sresource
    @pytest.mark.event
    @pytest.mark.parametrize('eventinfo', YamlUtil().read_testcase_yaml(
        'v25.06/resourcemanage/event/2_get_event_by_kind_exception.yaml'))
    def test_get_event_by_kind_exception(self, eventinfo):
        # 通过类型查找event-异常
        base_url = datas.baseUrl + Testevent.url_unify
        url = base_url + eventinfo['request']['url'].replace('{kind}', 'Pod')
        method = eventinfo['request']['method']
        req = RequestUtil().send_request(method, url)
        assert req.status_code == eventinfo['validate'][0]['equals']['status_code']

    @pytest.mark.normal
    @pytest.mark.k8sresource
    @pytest.mark.event
    @pytest.mark.parametrize('eventinfo',
                             YamlUtil().read_testcase_yaml('v25.06/resourcemanage/event/3_get_event_of_namespace.yaml')
                             )
    def test_get_event_of_namespace(self, eventinfo):
        # 获取某个命名空间下的event列表-正常
        base_url = datas.baseUrl + Testevent.url_unify
        url = base_url + eventinfo['request']['url'].replace('{namespace}', 'default')
        method = eventinfo['request']['method']
        req = RequestUtil().send_request(method, url)
        assert req.status_code == eventinfo['validate'][0]['equals']['status_code']

    @pytest.mark.abnormal
    @pytest.mark.k8sresource
    @pytest.mark.event
    @pytest.mark.parametrize('eventinfo', YamlUtil().read_testcase_yaml(
        'v25.06/resourcemanage/event/3_get_event_of_namespace_exception.yaml'))
    def test_get_event_of_namespace_exception(self, eventinfo):
        # 获取某个命名空间下的event列表-异常
        base_url = datas.baseUrl + Testevent.url_unify
        url = base_url + eventinfo['request']['url'].replace('{namespace}', 'default')
        method = eventinfo['request']['method']
        req = RequestUtil().send_request(method, url)
        assert req.status_code == eventinfo['validate'][0]['equals']['status_code']
